package com.javaerschool.lero.controller;

import com.javaerschool.lero.pojo.Admin;
import com.javaerschool.lero.service.AdminServiceI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 作者: lero
 * 日期：2018/7/25
 */
@Controller
public class AdminController {
    //定义一个使用Slfj实现的全局的日志记录器
    private static final Logger logger = LoggerFactory.getLogger(AdminController.class);

    @Autowired
    private AdminServiceI adminServiceI;


    /**
     *功能描述:返回AJAX功能测试
     * @date 2018/7/25
     * @param
     * @return java.util.Map
     */

    @RequestMapping("/testReturnJson")
    @ResponseBody
    public Map testReturnJson(){
        HashMap map = new HashMap();
        map.put("username","lero");
        return  map;
    }

    /**
     *功能描述: 返回视图功能测试
     * @date 2018/7/25
     * @param map
     * @return java.lang.String
     */
    @RequestMapping("/testReturnView")
    public  String  testReturnView(Map map){
        Admin admin = new Admin();
        admin.setId(1);
        admin.setUsername("LERO");
        map.put("admin",admin);
        return "index";
    }

    /**
     *功能描述: 和Mybatis整合测试
     * @date 2018/7/25
     * @param
     * @return int
     */
    @RequestMapping("/testInsert")
    @ResponseBody
    public int testInsert(){
        Admin admin = new Admin();
        admin.setUsername("javaschool.com");
        admin.setPassword("admin");
        return adminServiceI.insert(admin);
    }

    /**
     *功能描述: 和Mybatis整合测试
     * @date 2018/7/25
     * @param
     * @return int
     */
    @RequestMapping("/testLogback")
    @ResponseBody
    public void testLogback(){
        logger.debug("===>{}日志测试<===","lero");
    }

}
